package com.dzx.design.creational.prototype.clone;

/**
 * @author dzx
 * @ClassName:
 * @Description: 原型模式
 * @date 2019年07月15日 10:02:06
 */

import java.io.Serializable;

/**
 * 饿汉式+静态代码块
 */
public class SingletonExample4 implements Serializable,Cloneable {

    private SingletonExample4() {
    }

    /**
     * 防止通过反射和克隆方法破坏单例模式
     * @return
     * @throws CloneNotSupportedException
     */
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return getInstance();
    }

    private static SingletonExample4 singletonExample4 = null;

    static {
        singletonExample4 = new SingletonExample4();
    }

    public static SingletonExample4 getInstance() {
        return singletonExample4;
    }


}
